<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../common/css/insert.css">
<style type="text/css">
	td,th,tr {
		border:solid #428bca; 
		border-width:0px 1px 1px 0px;
		text-align:center;
		line-height:30px;
		overflow:hidden;
	}
	
	table {
		border:solid #428bca; 
		border-width:1px 0px 0px 1px;
		width:90%;
	}
	
	button {
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    background-color: #d9534f;
    border-color: #d43f3a; 
    color: #fff;
    display: inline-block;
    font-weight: 400;
    text-align: center;
    cursor: pointer;
    border: 1px solid transparent;
    font-size: 14px;
    line-height: 1.4285;
    border-radius: 4px;
}
	
</style>
<title>Users</title>
</head>
<body onload="tosearch()">
	<div>
		<label>结果显示：</label>
	</div>
	<div>
		<table id="searchResults">
		</table>
	</div>
	
	<script src="../js/jquery-1.9.1.min.js"></script>  
	<script src="../js/jquery.form.js"></script> 
	<script>
	function tosearch(){
		$(document).ready(function() {

			var jo={
				"userid":"",
				"nickname":"",
				"gender":"",
			};

			$.ajax({
				type : "post",
				url : "../getUserList.action",
				dataType : "json",
				data: jo,
				success : function(data) {
					

					var table = document.getElementById('searchResults');
					
					var users = data.users;
					//循环行
					for(var i=0;i<=users.length;i++){
						var tr = document.createElement('tr');

						if(i==0){
				            
				           	 var thUserId = document.createElement('th');
							 var thNickName = document.createElement('th');
							// var thStatus = document.createElement('th');
					         var thEmail = document.createElement('th');
					         var thUserCover = document.createElement('th');
					         var thGender = document.createElement('th');
					         var thDelete = document.createElement('th');

				            thUserId.innerHTML='用户ID';
				       		thNickName.innerHTML='用户昵称';
				       		//thStatus.innerHTML='用户类型';
				       		thEmail.innerHTML='邮箱';
				       		thUserCover.innerHTML='用户头像';
				       		thGender.innerHTML='性别';
				       		thDelete.innerHTML='删除按钮';
				            
				            tr.appendChild(thUserId);
				             tr.appendChild(thNickName);
					        // tr.appendChild(thStatus);
					         tr.appendChild(thEmail);
					         tr.appendChild(thUserCover);
					         tr.appendChild(thGender);
					         tr.appendChild(thDelete);
					        
						}else{
			            	
			            	
			            	// deleteButton.innerHTML='删除';
				            var tdUserId = document.createElement('td');
							 var tdNickName = document.createElement('td');
							 //var tdStatus = document.createElement('td');
					         var tdEmail = document.createElement('td');
					         var tdUserCover = document.createElement('td');
					         var tdGender = document.createElement('td');
					         var deleteButton = document.createElement('button');

				            tdUserId.innerHTML=users[i-1].userid;
				       		tdNickName.innerHTML=users[i-1].nickname;
				       		//tdStatus.innerHTML=users[i-1].status;
				       		tdEmail.innerHTML=users[i-1].email;
				       		tdUserCover.innerHTML=users[i-1].usercover;
				       		tdGender.innerHTML=users[i-1].gender;
				       		deleteButton.innerHTML='删除';
				            
				            tr.appendChild(tdUserId);
				             tr.appendChild(tdNickName);
					        // tr.appendChild(tdStatus);
					         tr.appendChild(tdEmail);
					         tr.appendChild(tdUserCover);
					         tr.appendChild(tdGender);
					         tr.appendChild(deleteButton);
 
				            
					         // tr.appendChild(deleteButton);

					         $(deleteButton).click(function(){
					        	 var row = $(this).parent()[0].rowIndex;
					        	 var userid=table.rows[row].cells[0].innerHTML;
					        	 var jo1={
					        		"userid":userid
					        	 };
					        	 
					        	 
					        	 $.ajax({
					     			type : "post",
					     			url : "../deleteUser.action",
					     			dataType : "json",
					     			data : jo1,
					     			success : function(data) {
					     				if(data.status=="succeed"){
					     					alert("删除成功");
					     					location.reload();
					     					
					     					
					     				}else if(data.status=="failed"){
					     					alert(data.reason);
					     				}
					     				
					     			}
					        	 });
					         });
						}
						
						table.appendChild(tr);
					}

				}
			});
		});
	}
	</script>
</body>
</html>